package com.cloudsigns.factorymanager2.produce.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cloudsigns.factorymanager2.BaseActivity;
import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.engineering.customview.DateViewDialog;

import java.util.Calendar;
import java.util.Locale;

public class ProduceWorkpartReturnDealInformationActivity extends BaseActivity {
    private RelativeLayout rl_back;
    private TextView tv_title;
    private EditText edt_return_num, edt_return_start_date, edt_return_complete_date, edt_scrap_num, edt_scrap_start_date, edt_scrap_complete_date;
    private ImageView img_return_start_date, img_return_complete_date, img_scrap_start_date, img_scrap_complete_date;
    private RadioGroup rg_return, rg_scrap;
    private RadioButton rb_yes, rb_no, rb_return, rb_renew;
    private Button btn_save;

    @Override
    protected void onBaseCreate(Bundle savedInstanceState) {
        setContentView(R.layout.layout_produce_workpart_return_deal_information);
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        rl_back = findViewById(R.id.rl_back);
        tv_title = findViewById(R.id.tv_title);
        edt_return_num = findViewById(R.id.edt_return_num);
        edt_return_start_date = findViewById(R.id.edt_return_start_date);
        edt_return_complete_date = findViewById(R.id.edt_return_complete_date);
        img_return_start_date = findViewById(R.id.img_return_start_date);
        img_return_complete_date = findViewById(R.id.img_return_complete_date);
        edt_scrap_num = findViewById(R.id.edt_scrap_num);
        edt_scrap_start_date = findViewById(R.id.edt_scrap_start_date);
        edt_scrap_complete_date = findViewById(R.id.edt_scrap_complete_date);
        img_scrap_start_date = findViewById(R.id.img_scrap_start_date);
        img_scrap_complete_date = findViewById(R.id.img_scrap_complete_date);
        rg_return = findViewById(R.id.rg_return);
        rg_scrap = findViewById(R.id.rg_scrap);
        rb_yes = findViewById(R.id.rb_yes);
        rb_no = findViewById(R.id.rb_no);
        rb_return = findViewById(R.id.rb_return);
        rb_renew = findViewById(R.id.rb_renew);
        btn_save = findViewById(R.id.btn_save);
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        tv_title.setText(getResources().getString(R.string.deal_information));
    }

    @Override
    public void setListener() {
        rl_back.setOnClickListener(this);
        img_return_start_date.setOnClickListener(this);
        img_return_complete_date.setOnClickListener(this);
        img_scrap_start_date.setOnClickListener(this);
        img_scrap_complete_date.setOnClickListener(this);
        btn_save.setOnClickListener(this);
    }

    // 返工周期 开工日期
    private void showReturnStartDateDialog() {
        DateViewDialog endDateChooseDialog = new DateViewDialog(this,
                new DateViewDialog.DateChooseInterface() {
                    @Override
                    public void getDateTime(String time, boolean longTimeChecked) {
                        edt_return_start_date.setText(time);
                    }
                });
        endDateChooseDialog.setTimePickerGone(true);

        Calendar dateAndTime = Calendar.getInstance(Locale.getDefault());
        endDateChooseDialog.setDateDialogTitle(dateAndTime.get(Calendar.YEAR) + "-" + (dateAndTime.get(Calendar.MONTH) + 1) + "-" + dateAndTime.get(Calendar.DAY_OF_MONTH));
        endDateChooseDialog.showDateChooseDialog();
    }

    // 返工周期 完工日期
    private void showReturnCompletionDateDialog() {
        DateViewDialog endDateChooseDialog = new DateViewDialog(this,
                new DateViewDialog.DateChooseInterface() {
                    @Override
                    public void getDateTime(String time, boolean longTimeChecked) {
                        edt_return_complete_date.setText(time);
                    }
                });
        endDateChooseDialog.setTimePickerGone(true);

        Calendar dateAndTime = Calendar.getInstance(Locale.getDefault());
        endDateChooseDialog.setDateDialogTitle(dateAndTime.get(Calendar.YEAR) + "-" + (dateAndTime.get(Calendar.MONTH) + 1) + "-" + dateAndTime.get(Calendar.DAY_OF_MONTH));
        endDateChooseDialog.showDateChooseDialog();
    }

    // 报废周期 开工日期
    private void showScrapStartDateDialog() {
        DateViewDialog endDateChooseDialog = new DateViewDialog(this,
                new DateViewDialog.DateChooseInterface() {
                    @Override
                    public void getDateTime(String time, boolean longTimeChecked) {
                        edt_scrap_start_date.setText(time);
                    }
                });
        endDateChooseDialog.setTimePickerGone(true);

        Calendar dateAndTime = Calendar.getInstance(Locale.getDefault());
        endDateChooseDialog.setDateDialogTitle(dateAndTime.get(Calendar.YEAR) + "-" + (dateAndTime.get(Calendar.MONTH) + 1) + "-" + dateAndTime.get(Calendar.DAY_OF_MONTH));
        endDateChooseDialog.showDateChooseDialog();
    }

    // 报废周期 完工日期
    private void showScrapCompletionDateDialog() {
        DateViewDialog endDateChooseDialog = new DateViewDialog(this,
                new DateViewDialog.DateChooseInterface() {
                    @Override
                    public void getDateTime(String time, boolean longTimeChecked) {
                        edt_scrap_complete_date.setText(time);
                    }
                });
        endDateChooseDialog.setTimePickerGone(true);

        Calendar dateAndTime = Calendar.getInstance(Locale.getDefault());
        endDateChooseDialog.setDateDialogTitle(dateAndTime.get(Calendar.YEAR) + "-" + (dateAndTime.get(Calendar.MONTH) + 1) + "-" + dateAndTime.get(Calendar.DAY_OF_MONTH));
        endDateChooseDialog.showDateChooseDialog();
    }

    @Override
    public void widgetClick(View view) {
        switch (view.getId()) {
            case R.id.rl_back:
                finish();
                break;
            // 返工周期 开工日期
            case R.id.img_return_start_date:
                showReturnStartDateDialog();
                break;
            // 返工周期 完工日期
            case R.id.img_return_complete_date:
                showReturnCompletionDateDialog();
                break;
            // 报废周期 开工日期
            case R.id.img_scrap_start_date:
                showScrapStartDateDialog();
                break;
            // 报废周期 完工日期
            case R.id.img_scrap_complete_date:
                showScrapCompletionDateDialog();
                break;
            // 保存
            case R.id.btn_save:
                break;
        }
    }
}
